<script setup>
import { ref } from 'vue'

const newTodo = ref('')
const newTodoDesc = ref('')
const newTag = ref('')
const todos = ref([])
const editingTodoId = ref(null)

const addTodo = () => {
  if (newTodo.value.trim()) {
    todos.value.push({
      id: Date.now(),
      text: newTodo.value,
      description: newTodoDesc.value,
      completed: false,
      favorite: false,
      tags: [],
      showTagInput: false
    })
    newTodo.value = ''
    newTodoDesc.value = ''
  }
}

const toggleTodo = (todo) => {
  todo.completed = !todo.completed
}

const toggleFavorite = (todo) => {
  todo.favorite = !todo.favorite
}

const toggleTagInput = (todo) => {
  todo.showTagInput = !todo.showTagInput
}

const addTag = (todo) => {
  if (newTag.value.trim() && !todo.tags.includes(newTag.value.trim())) {
    todo.tags.push(newTag.value.trim())
    newTag.value = ''
  }
}

const removeTag = (todo, tag) => {
  todo.tags = todo.tags.filter(t => t !== tag)
}

const deleteTodo = (id) => {
  todos.value = todos.value.filter(todo => todo.id !== id)
}
</script>

<template>
  <router-view></router-view>
</template>

<style scoped>
.todo-app {
  max-width: 600px;
  margin: 40px auto;
  padding: 24px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  border-radius: 12px;
  background-color: #ffffff;
  transition: all 0.3s ease;
}

.todo-app:hover {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
}

h1 {
  color: #1d1d1f;
  text-align: center;
  margin-bottom: 24px;
  font-weight: 500;
  font-size: 28px;
}

.input-container {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

.input-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.title-input {
  width: 100%;
  padding: 10px 16px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  font-size: 15px;
  background-color: #f5f5f7;
  transition: all 0.2s ease;
}

.desc-input {
  width: 100%;
  padding: 10px 16px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  font-size: 14px;
  background-color: #f5f5f7;
  transition: all 0.2s ease;
  resize: vertical;
}

.title-input:focus,
.desc-input:focus {
  outline: none;
  border-color: #0071e3;
  background-color: #ffffff;
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.1);
}

.add-btn {
  background-color: #0071e3;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
  transition: all 0.2s ease;
  align-self: flex-start;
}

.add-btn:hover {
  background-color: #0077ed;
  transform: translateY(-1px);
}

.add-btn:active {
  transform: translateY(0);
}

.todo-list {
  list-style: none;
  padding: 0;
}

.todo-list li {
  display: flex;
  flex-direction: column;
  padding: 14px 16px;
  background-color: #f5f5f7;
  margin-bottom: 10px;
  border-radius: 8px;
  gap: 12px;
  transition: all 0.2s ease;
}

.todo-main {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.todo-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.todo-text {
  font-size: 15px;
  color: #1d1d1f;
  transition: all 0.2s ease;
}

.todo-description {
  font-size: 13px;
  color: #86868b;
  margin: 0;
  line-height: 1.4;
}

.todo-tags {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-left: 45px;
}

.tags-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background-color: #e0e0e0;
  border-radius: 12px;
  font-size: 12px;
  color: #1d1d1f;
}

.add-tag-btn {
  border: none;
  background: none;
  color: #0071e3;
  font-size: 12px;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 12px;
}

.add-tag-btn:hover {
  background-color: rgba(0, 113, 227, 0.1);
}

.remove-tag {
  border: none;
  background: none;
  color: #86868b;
  cursor: pointer;
  padding: 0 2px;
  font-size: 14px;
  line-height: 1;
}

.remove-tag:hover {
  color: #ff3b30;
}

.add-tag {
  display: flex;
  gap: 6px;
}

.tag-input {
  flex: 1;
  padding: 4px 8px;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  font-size: 12px;
  background-color: #ffffff;
}

.tag-input:focus {
  outline: none;
  border-color: #0071e3;
  box-shadow: 0 0 0 2px rgba(0, 113, 227, 0.1);
}

.tag-btn {
  border: none;
  background-color: #0071e3;
  color: white;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.favorite-btn {
  border: none;
  background: none;
  cursor: pointer;
  padding: 4px 8px;
  font-size: 18px;
  color: rgba(142, 142, 147, 0.8);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 6px;
  align-self: flex-start;
}

.favorite-btn:hover {
  transform: scale(1.1);
  background-color: rgba(0, 113, 227, 0.1);
  color: #0071e3;
}

.favorite-btn.active {
  color: #0071e3;
  background-color: rgba(0, 113, 227, 0.1);
}

.favorite-btn .star {
  display: inline-block;
  line-height: 1;
  transform-origin: center;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.favorite-btn.active .star {
  transform: scale(1.2);
}

.favorite .todo-text {
  color: #0071e3;
  font-weight: 500;
}

.todo-list li:hover {
  background-color: #f0f0f2;
}

.checkbox-container {
  display: inline-block;
  position: relative;
  padding-left: 25px;
  cursor: pointer;
  user-select: none;
  align-self: flex-start;
  margin-top: 2px;
}

.checkbox-container input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  height: 0;
  width: 0;
}

.checkmark {
  position: absolute;
  top: -8px;
  left: 0;
  height: 18px;
  width: 18px;
  background-color: #ffffff;
  border: 1px solid #d1d1d1;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.checkbox-container:hover input ~ .checkmark {
  border-color: #0071e3;
}

.checkbox-container input:checked ~ .checkmark {
  background-color: #0071e3;
  border-color: #0071e3;
}

.checkmark:after {
  content: "";
  position: absolute;
  display: none;
}

.checkbox-container input:checked ~ .checkmark:after {
  display: block;
  left: 6px;
  top: 2px;
  width: 4px;
  height: 9px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.completed .todo-text {
  text-decoration: line-through;
  color: #86868b;
}

.completed .todo-description {
  text-decoration: line-through;
}

.delete-btn {
  background-color: #ff3b30;
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  opacity: 0.9;
  transition: all 0.2s ease;
  align-self: flex-start;
}

.delete-btn:hover {
  opacity: 1;
  transform: translateY(-1px);
}

.delete-btn:active {
  transform: translateY(0);
}
</style>
